package org.example.studentmanager.controller;

import org.example.studentmanager.common.utils.R;
import org.example.studentmanager.entity.LoginInfo;
import org.example.studentmanager.entity.User;
import org.example.studentmanager.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @PostMapping("/user/login")
    public LoginInfo login(@RequestBody User user) {
        // 记录请求参数
        logger.info("接收到登录请求，请求参数: {}", user);
        LoginInfo loginInfo = userService.login(user);
        // 记录返回结果
        logger.info("登录请求处理完成，返回结果: {}", loginInfo);
        return loginInfo;
    }

    // 修改密码接口
    @PostMapping("/update")
    public R<Boolean> updatePassword(@RequestBody User user) {
        if (user.getPassword() == null) {

        }
        return R.success( userService.updatePassword(user.getUsername(), user.getPassword()));
    }
}
